<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    Function.prototype.myApply = function (thisArg) {
      thisArg = thisArg || window
      thisArg.fn = this // thisArg.fn指向this也就是指向调用它的对象
      let res
      if (arguments[1]) {
        res = thisArg.fn(...arguments[1])
      } else {
        res = thisArg.fn()
      }
      delete thisArg.fn // 离开之前要删除掉
      return res
    }
//-------------------------------------------------------------------------------------------
    // 练习区：
    

    function add(a, b) {
      console.log(this, a + b);
    }
    let res1 = add.myApply(null, [1, 2])
    let res2 = add.myApply({a: 4, b: 3}, [2, 3])

  </script>
</body>
</html>